package worker.model.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import worker.model.vo.HistoryVO;
import worker.model.vo.ItemInfoVO;
import worker.model.vo.SearchConditionVO;
import worker.model.vo.WipVO;
import worker.model.vo.WorkOrdersVO;

import com.ibatis.sqlmap.client.SqlMapClient;

public class ProcessDao {
	private SqlMapClient sqlMapClient;

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	/**
	 * history tabld에 등록
	  */
	public void insertHistory(HistoryVO hisVO) throws SQLException {
		sqlMapClient.insert("process.insertHistory",hisVO);		
	}
	/**
	 * 최초 wip table 삽입
	 */
	public void insertWip(WipVO vo) throws SQLException {
		sqlMapClient.insert("process.insertWip",vo);		
	}

	/**
	 * 결함생긴 item 가져오기
	 */
	public ArrayList<HashMap> getFailNoInWip() throws SQLException {
		return (ArrayList<HashMap>) sqlMapClient.queryForList("process.getFailNoInWip");
	}

	/**
	 * 정상 수행된 item에 대해서 wip update
	 * @throws SQLException 
	 */
	public void updateWip(WipVO vo) throws SQLException {
		sqlMapClient.update("process.updateWip",vo);		
	}

	public String getCompleteWorkOrder(String id) throws SQLException {
		return (String) sqlMapClient.queryForObject("process.getCompleteWorkOrder",id);
	}
		/**
	 * wip 테이블에서 complete 된 것만 받아오기
	 * @throws SQLException 
	*/
	public int getCompleteQtyInWip() throws SQLException {
		return (Integer) sqlMapClient.queryForObject("process.getCompleteQtyInWip");
	}
	/**
	 * wip table 비우기
	 * @throws SQLException 
	 */
	public void deleteWip() throws SQLException {
		sqlMapClient.delete("process.deleteWip");
	}
	/**
	 * 이미 존재하는 에러인가?
	 */
	public Object isExistErrorInWip(WipVO wip) throws SQLException {
		return sqlMapClient.queryForObject("process.isExistErrorInWip",wip);
	}
	/**
	 * op1의 history에서 성공qty
	 */
	public int getOP1SuccessInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj= sqlMapClient.queryForObject("process.getOP1SuccessInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * op1의 history에서 실패qty
	*/
	public int getOP1FailInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj = sqlMapClient.queryForObject("process.getOP1FailInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * 1공정에서 결함 serial_no get
	 */
	public ArrayList<String> getOP1FailSerialNo(SearchConditionVO vo) throws SQLException {
		ArrayList<String> list = (ArrayList<String>) sqlMapClient.queryForList("process.getOP1FailSerialNo",vo);
		if(list==null){
			list=new ArrayList<String>();list.add("dont search");
		}
		return list;
	}
	/**
	 * operation2 ->성공 qty
	 */
	public int getOP2SuccessInfoInHistory(SearchConditionVO vo) throws SQLException {
		
		Object obj= sqlMapClient.queryForObject("process.getOP2SuccessInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * operation2 ->실패 qty
	 */
	public int getOP2FailInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj = sqlMapClient.queryForObject("process.getOP2FailInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * operation2 실패 serial_no
	*/
	public ArrayList<String> getOP2FailId(SearchConditionVO vo) throws SQLException {
		return (ArrayList<String>) sqlMapClient.queryForList("process.getOP2FailId",vo);
	}

	/**
	 * operation3 ->성공수
	 */
	public int getOP3SuccessInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj =  sqlMapClient.queryForObject("process.getOP3SuccessInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * operation3 ->실패 qty
	 */
	public int getOP3FailInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj = sqlMapClient.queryForObject("process.getOP3FailInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * operation3 실패 serial_no
	*/
	public ArrayList<String> getOP3FailId(SearchConditionVO vo) throws SQLException {
		ArrayList<String> list =  (ArrayList<String>) sqlMapClient.queryForList("process.getOP3FailId",vo);
		if(list==null){
			list=new ArrayList<String>();list.add("dont search");
		}
		return list;
	}
	/**
	 * op4성공 qty
	*/
	public int getOP4SuccessInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj = sqlMapClient.queryForObject("process.getOP4SuccessInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * op4 실패 qty
	 */
	public int getOP4FailInfoInHistory(SearchConditionVO vo) throws SQLException {
		Object obj = sqlMapClient.queryForObject("process.getOP4FailInfoInHistory",vo);
		if(obj==null){
			return 0;
		}else{
			return (Integer)obj;
		}
	}
	/**
	 * op4 실패 serial_no
	 */
	public ArrayList<String> getOP4FailId(SearchConditionVO vo) throws SQLException {
		ArrayList<String> list = (ArrayList<String>) sqlMapClient.queryForList("process.getOP4FailId",vo);
		if(list==null){
			list=new ArrayList<String>();list.add("dont search");
		}
		return list;
	}
	/**
	 * 시작 serial_no받아오기
	 */
	public String getStartNo(String wO) throws SQLException {
		return (String) sqlMapClient.queryForObject("process.getStartNo",wO);
	}
	
	/**
	  * 재고 업데이트 - 공정에 사용한 재료 빼기
	  * @throws SQLException 
	  */
	 public void updateMaterial(ItemInfoVO iivo) throws SQLException {
	  this.sqlMapClient.update("process.updateMaterial",iivo);
	  
	 }

	
	
	
	
	

	
}
